package org.cmg.study.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.cmg.study.mybatis.entity.User;

import java.util.List;

/**
 * @author CMG
 * @version 1.0
 * @cLassName UserMapper
 * @description
 * @date 2021/9/7 10:55
 **/
public interface UserMapper {
    @Select("Select * from user")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "age", property = "age")
    })
    List<User> queryAllUser();

    @Insert("insert into user(name, sex, age) values(#{name},#{sex},#{age})")
    int insert(User user);

    @Insert("insert into user(id,name,age) values(#{id},#{name},#{age})")
    @SelectKey(statement = "select last_insert_id()", keyProperty = "id", keyColumn = "id", before = false, resultType = int.class)
    int insert1(User user);

    @Update("update user set name= #{name},sex = #{sex},age =#{age} where id = #{id}")
    int updateUserById(User user);

    @Delete("delete from  user  where id =#{id}")
    int deleteById(Integer id);

}
